<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/2 0002
 * Time: 15:11
 */

namespace app\common\service;

class BaseService
{
    /**
     * @param $message_flag
     * @param array $data
     * @return array
     */
    protected static function msg($message_flag, $data = [])
    {
        $config = isset(config('message')[$message_flag]) ? config('message')[$message_flag] : config('message')['ERROR'];
        $return = [
            'code' => $config['code'],
            'msg' => $config['msg'],
            'data' => $data,
        ];
        return $return;
    }

    /**
     * @param $bool [true  or false]
     * @param string $flag
     * @return array
     */
    protected static function boolMsg($bool, $flag = 'add')
    {
        switch ($flag) {
            case 'add':
                $success_msg = 'ADD_SUCCESS';
                $error_msg = 'ADD_ERROR';
                break;
            case 'edit':
                $success_msg = 'SAVE_SUCCESS';
                $error_msg = 'SAVE_ERROR';
                break;
            case 'cancel':
                $success_msg = 'CANCEL_SUCCESS';
                $error_msg = 'CANCEL_ERROR';
                break;
            case 'favorite':
                $success_msg = 'FAVORITE_REPEAT_SUCCESS';
                $error_msg = 'FAVORITE_REPEAT_ERROR';
                break;
            default:
                $success_msg = '';
                $error_msg = '';
        }
        if ($bool) {
            $return = self::msg($success_msg);
        } else {
            $return = self::msg($error_msg);
        }
        return $return;
    }


}